/*******************************************************************************
 * Copyright (C) 2010 Devin Samarin.
 * 
 * This file is part of the SUIT Toolkit.
 * 
 * The SUIT Toolkit is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * The SUIT Toolkit is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with the SUIT Toolkit.  If not, see <http://www.gnu.org/licenses/>.
 ******************************************************************************/
package suit.ui;

/**
 * A toggle button widget that consists of a Check box and the child (label,
 * etc).
 * 
 * CheckButtons are similar to ToggleButtons, but look very different. Contrary
 * to ToggleButtons, which are Buttons with text inside them, they are small
 * check squares, with descriptive text beside them. As with ToggleButtons, they
 * can be used to toggle options on or off.
 * 
 * CheckButtons derive from ToggleButtons and hence behave somewhat similarly.
 * 
 * The choice between a CheckButton and a ToggleButton is left to the
 * developer's discretion. A CheckButton can take considerably lesser space than
 * a ToggleButton. A CheckButton is more useful when you have a list of related
 * options that need to be set or unset. A ToggleButton could be used when a
 * single option needs to be toggled.
 * 
 * @author Devin Samarin
 * 
 */
public class CheckButton extends ToggleButton {

	protected int boxSize = 20;

	/**
	 * Construct a new CheckButton
	 */
	public CheckButton() {
	}

	/**
	 * Construct a new CheckButton with a label automatically put inside
	 * 
	 * @param text
	 *            the text of the label that is placed to the side of the check
	 *            mark
	 */
	public CheckButton(String text) {
		super(text);
	}

	protected boolean onExpose(Event e) {
		if (active)
			e.graphics.setColor(0xcecece);
		else
			e.graphics.setColor(0xFFFFFF);
		e.graphics.fillRect(allocation.x, allocation.y + allocation.h / 2
				- boxSize / 2, boxSize, boxSize);
		e.graphics.setColor(0xbcbcbc);
		e.graphics.drawRect(allocation.x, allocation.y + allocation.h / 2
				- boxSize / 2, boxSize - 1, boxSize - 1);
		// g.setColor(0xe8e8e8);
		// g.drawLine(allocation.x+1, allocation.y + allocation.h/2 - boxSize/2
		// +1, allocation.x + allocation.w-2, allocation.y +1);
		if (children != null) {
			Widget w = ((Widget) children.firstElement());
			w.sizeAllocate(new Rectangle(allocation.x + boxSize, allocation.y,
					allocation.w - boxSize, allocation.h));
			w.registerEvent(e);
		}
		return false;
	}

}
